package com.googlecode.gwt4gae.client;

import java.util.HashMap;
import java.util.Map;

import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.Dispatcher;

public class ActionRegistry {
	private static Map<String, EventType> ACTION_EVENT_TYPE = new HashMap<String, EventType>();
	
	public static void registAction(BaseAction action) {
		/*try {
			Class<?> actionClass = Class.forName(actionName);
			BaseAction action = (BaseAction) GWT.create(actionClass);
			EventType eventType = new EventType();
			action.registerEventTypes(eventType);
			ACTION_EVENT_TYPE.put(actionName, eventType);
			Dispatcher dispatcher = Dispatcher.get();
			dispatcher.addController(action);
		} catch (Exception e) {
			GWT.log("注册Action失败", e);
		}*/
		
		EventType eventType = new EventType();
		action.registerEventTypes(eventType);
		ACTION_EVENT_TYPE.put(action.getClass().getName(), eventType);
		Dispatcher dispatcher = Dispatcher.get();
		dispatcher.addController(action);
	}
	
	public static EventType getActionEventType(String actionName) {
		return ACTION_EVENT_TYPE.get(actionName);
	}
}
